package net.csdn.business.discuss.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.csdn.business.discuss.api.model.entity.DiscussAnswerRecord;
import net.csdn.business.discuss.api.model.vo.AnswerSortVO;
import net.csdn.business.discuss.api.model.vo.DiscussAnswerRecordVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 讨论采纳问题记录Mapper接口
 * 
 * @author ruoyi
 * @date 2023-07-25
 */
public interface DiscussAnswerRecordMapper extends BaseMapper<DiscussAnswerRecord>
{
    

    /**
     * 查询讨论采纳答案信息
     * 
     * @param discussId 讨论采纳答案信息主键
     * @return 讨论采纳答案信息
     */
    @Select("select * from discuss_answer_record where discuss_id=#{discussId}")
    public DiscussAnswerRecordVO selectVoteByDiscussId(String discussId);
    
    /**
     * 根据讨论id,删除讨论采纳答案信息
     * 
     * @param discussId 讨论主键
     * @return 结果
     */
    @Delete("delete from discuss_answer_record where discuss_id=#{discussId}")
    public Integer deleteAnswerRecordByDiscussId(String discussId);


    /**
     * 查询讨论最近30天采纳答案的排行
     *
     * @param sourceId 所属资源id
     * @param sourceType 所属资源类型
     * @return 讨论采纳答案信息
     */
    @Select("select count(*) as total,user_id from discuss_answer_record where source_id=#{sourceId} and source_type=#{sourceType} and created_date  BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW() group by user_id order by total desc limit 5")
    public List<AnswerSortVO> selectAnswerSortByDiscussId(@Param("sourceId") String sourceId, @Param("sourceType")Integer sourceType);
}
